#ifndef PRIVATE_DATA_MANAGER_H
#define PRIVATE_DATA_MANAGER_H
#include <qglobal.h>
#include <qmap.h>
#include <qobject.h>
#include <osgViewer/Viewer>
#include <osgWidget/WindowManager>
#include <osgEarthUtil/EarthManipulator>
#include <osgEarthUtil/Ocean.h>
#include <osgEarth/Map>
#include "Def.h"
#include "SDKCore.h"
#include "env/Sky.h"
#include "widget/MainWindow.h"
#include "HelperPrivate.h"
#include "HandlePrivate.h"
#include "script/ScriptExecutorPrivate.h"
#include "text/TextPrivate.h"
#include "style/StyleManagerPrivate.h"
#include "earth/EarthGraticulePrivate.h"
#include "layer/LayerManagerPrivate.h"

struct SnapImage;
class HandlerPrivate;

class SDKCorePrivate : public QObject,public ScriptHelper
{
	Q_OBJECT
	DECLARE_PUBLIC(SDKCore)
	friend class HandlePrivate;
public:
	SDKCorePrivate(SDKCore* sdkcore);

	void setMainWindow(MainWindow* widget);
	void onClickAddon();

	bool initial();
public:
	QString getPackage()const { return "SDKCore"; }
	QString getModule()const { return "SDKCore"; }

	osgViewer::Viewer* getOsgView()const{return osgView;}
	osg::Group* getOsgRootNode()const{return osgRoot;}
	osgEarth::MapNode* getOsgMapNode()const{return osgMapNode;}

	osg::Group* getOsgAnnoGroup()const{return osgAnnoGroup;}
	osg::Group* getOsgLabelGroup()const{return osgLabelGroup;}
	osg::Group* getOsgEditGroup()const{return osgEditGroup;}

	osgWidget::WindowManager* getOsgWindowManager()const { return windowManager; }
	osgEarth::Util::EarthManipulator* getEarthManipulator()const { return earthManipulator; }
	ICamera* getCamera()const { return camera; }
	osg::Camera* getOsgHudCamera()const{return osgHudCamera;}
	osg::Geode* getOsgHudGeode()const{return osgHudGeode;}

	Helper* getHelper()const { return helper; }
	ScriptExecutor* getScriptExecutor()const{return scriptExecutor;}
	Text* getText()const { return text; }
	StyleManager* getStyleManager()const { return styleManager; }
	EarthGraticule* getEarthGraticule()const { return earthGraticule; }
	LayerManager* getLayerManager()const {return layerManager;}

	osgEarth::Util::OceanNode* getOcean()const{return oceanNode;}
public:
	void onWindowResize(int width,int height);


	void asyncCaptureImage(const QString& file,std::function<void(const QString&,bool)> fn);
	bool asyncCaptureImage(const QStringList& argument,QString* error = nullptr);

	bool writeToLog(const QStringList& argument,QString* error = nullptr);
signals:
	void setAddonClick();
private:
	void createHudCamera();
private:
	MainWindow* mainWidget = nullptr;

	osgViewer::Viewer* osgView = nullptr;
	osg::Group* osgRoot = nullptr;
	osg::Group* osgAnnoGroup = nullptr;
	osg::Group* osgLabelGroup = nullptr;
	osg::Group* osgEditGroup = nullptr;
	osg::Camera* osgHudCamera = nullptr;
	osg::Geode* osgHudGeode = nullptr;

	osgEarth::MapNode* osgMapNode = nullptr;
	osgWidget::WindowManager* windowManager = nullptr;
	osgEarth::Util::EarthManipulator* earthManipulator = nullptr;
	ICamera* camera = nullptr;

	Sky* sky = nullptr;
	osgEarth::Util::OceanNode* oceanNode = nullptr;
	HelperPrivate* helper = nullptr;
	ScriptExecutorPrivate* scriptExecutor = nullptr;
	TextPrivate* text = nullptr;
	StyleManagerPrivate* styleManager = nullptr;
	EarthGraticulePrivate* earthGraticule = nullptr;
	LayerManagerPrivate* layerManager = nullptr;

	HandlerPrivate* handlePrivate = nullptr;

	SnapImage* postDrawSnapImage = nullptr;
	SnapImage* finalDrawSnapImage = nullptr;
};

#define GLOBAL_OSG_VIEW SDKCore::instance()->d_func()->getOsgView()
#define GLOBAL_OSG_ROOT_NODE SDKCore::instance()->d_func()->getOsgRootNode()
#define GLOBAL_OSG_MAP_NODE SDKCore::instance()->d_func()->getOsgMapNode()

#define GLOBAL_OSG_HUD_CAMERA SDKCore::instance()->d_func()->getHudCamera()
#define GLOBAL_OSG_HUD_TEXT_GEODE SDKCore::instance()->d_func()->getHudTextGeode()

#define GLOBAL_OSG_ANNO_GROUP SDKCore::instance()->d_func()->getOsgAnnoGroup()
#define GLOBAL_OSG_LABEL_GROUP SDKCore::instance()->d_func()->getOsgLabelGroup()
#define GLOBAL_OSG_EDIT_GROUP SDKCore::instance()->d_func()->getOsgEditGroup()

#define GLOBAL_OSG_TEXT SDKCore::instance()->d_func()->getText()
#define GLOBAL_OSG_WINDOWMANAGER SDKCore::instance()->d_func()->getOsgWindowManager()
#define GLOBAL_OSG_EARTH_MANIPULATOR SDKCore::instance()->d_func()->getEarthManipulator()

#define GLOBAL_OSG_OCEAN SDKCore::instance()->d_func()->getOcean()

#endif